home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / game / wins1726.zip / PROFILE.C < prev    next >
C/C++ Source or Header  |  1992-06-06  |  4KB  |  165 lines

  1. #include <windows.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "winfract.h"
  5. #include "profile.h"
  6.  
  7. extern int xdots, ydots, Sizing;
  8. extern int ZoomBarOpen, CoordBoxOpen;
  9. extern BOOL winfract_menustyle;
  10. extern int win_fastupdate;
  11. static char None[]      = "None";
  12. static char SSTools[80];
  13. static char True[]      = "True";
  14. static char False[]     = "False";
  15. static char Yes[]       = "Yes";
  16. static char One[]       = "1";
  17. char FractintMenusStr[] = "FractintMenus";
  18. char FractintPixelsStr[] = "PixelByPixel";
  19.  
  20. static BOOL NoSave = FALSE;
  21.  
  22. char Winfract[]  = "Winfract";
  23. char Fractint[]  = "Fractint";
  24. char *ProgStr = Winfract;
  25.  
  26. void SetToolsPath(void) {
  27.    static char FileName[] = "sstools.ini";
  28.  
  29.    findpath(FileName, SSTools);
  30.    if(!*SSTools)
  31.       strcpy(SSTools, FileName);
  32. }
  33.  
  34. BOOL GetParamSwitch(char *Key) {
  35.    char Text[80];
  36.  
  37.    GetPrivateProfileString(ProgStr, Key, None, Text, sizeof(Text), SSTools);
  38.    if(!stricmp(Text, True) ||
  39.       !stricmp(Text, Yes) ||
  40.       !stricmp(Text, One)
  41.    ) return(TRUE);
  42.    return(FALSE);
  43. }
  44.  
  45. double GetFloatParam(char *Key, double Def) {
  46.    char Text[80];
  47.  
  48.    GetPrivateProfileString(ProgStr, Key, None, Text, sizeof(Text), SSTools);
  49.    if(!stricmp(None, Text))
  50.       return(Def);
  51.    return(atof(Text));
  52. }
  53.  
  54. double GetIntParam(char *Key, int Def) {
  55.    char Text[80];
  56.  
  57.    GetPrivateProfileString(ProgStr, Key, None, Text, sizeof(Text), SSTools);
  58.    if(!stricmp(None, Text))
  59.       return(Def);
  60.    return(atoi(Text));
  61. }
  62.  
  63. void SaveParamStr(char *Key, char *Str) {
  64.    if(!NoSave)
  65.       WritePrivateProfileString(ProgStr, Key, Str, SSTools);
  66. }
  67.  
  68. void SaveFloatParam(char *Key, double Num) {
  69.    char Str[80];
  70.  
  71.    sprintf(Str, "%g", Num);
  72.    SaveParamStr(Key, Str);
  73. }
  74.  
  75. void SaveIntParam(char *Key, int Num) {
  76.    char Str[80];
  77.  
  78.    sprintf(Str, "%d", Num);
  79.    SaveParamStr(Key, Str);
  80. }
  81.  
  82. void SaveParamSwitch(char *Key, BOOL Flag) {
  83.    char *Str;
  84.  
  85.    if(Flag)
  86.       Str = True;
  87.    else
  88.       Str = False;
  89.    SaveParamStr(Key, Str);
  90. }
  91.  
  92. void PositionWindow(HWND hWnd, char *Key) {
  93.    char Text[80];
  94.    POINT Pos;
  95.  
  96.    GetPrivateProfileString(Winfract, Key, None, Text, sizeof(Text), SSTools);
  97.    if(stricmp(Text, None)) {
  98.       sscanf(Text, "%d, %d", &Pos.x, &Pos.y);
  99.       NoSave = TRUE;
  100.       SetWindowPos(hWnd, GetNextWindow(hWnd, GW_HWNDPREV), Pos.x, Pos.y,
  101.                    0, 0, SWP_NOSIZE);
  102.       NoSave = FALSE;
  103.    }
  104. }
  105.  
  106. extern int ZoomMode;
  107.  
  108. void SaveWindowPosition(HWND hWnd, char *Key) {
  109.    char Text[80];
  110.    RECT Rect;
  111.  
  112.    GetWindowRect(hWnd, &Rect);
  113.    sprintf(Text, "%d, %d", Rect.left, Rect.top);
  114.    SaveParamStr(Key, Text);
  115. }
  116.  
  117. char WindowSizingStr[]     = "WindowSizing";
  118. char ImageWidthStr[]       = "ImageWidth";
  119. char ImageHeightStr[]      = "ImageHeight";
  120. char ZoomBoxStr[]          = "ZoomBoxOpen";
  121. char CoordBoxStr[]         = "CoordinateBoxOpen";
  122. char WinfractPosStr[]      = "WinfractPosition";
  123. char ZoomBoxPosStr[]       = "ZoomBoxPosition";
  124. char CoordBoxPosStr[]      = "CoordBoxPosition";
  125. char ZoomOutStr[]           = "ZoomOut";
  126.  
  127. void InitializeParameters(HWND hWnd) {
  128.    NoSave = TRUE;
  129.  
  130.    xdots = GetIntParam(ImageWidthStr, 200);
  131.    ydots = GetIntParam(ImageHeightStr, 150);
  132.  
  133.    winfract_menustyle = GetParamSwitch(FractintMenusStr);
  134.    win_fastupdate = 0;
  135.    if(GetParamSwitch(FractintPixelsStr))
  136.        win_fastupdate = 1;
  137.  
  138.    PositionWindow(hWnd, WinfractPosStr);
  139.    if(GetParamSwitch(WindowSizingStr) != Sizing)
  140.       WindowSizing(hWnd);
  141.  
  142.    if(GetParamSwitch(ZoomBoxStr) != ZoomBarOpen)
  143.       ZoomBar(hWnd);
  144.    else if(GetParamSwitch(ZoomOutStr))
  145.    {
  146.       CheckMenuItem(GetMenu(hWnd), IDM_ZOOMOUT, MF_CHECKED);
  147.       ZoomMode = IDM_ZOOMOUT;
  148.    }
  149.    else
  150.    {
  151.       CheckMenuItem(GetMenu(hWnd), IDM_ZOOMIN, MF_CHECKED);
  152.       ZoomMode = IDM_ZOOMIN;
  153.    }
  154.    if(GetParamSwitch(CoordBoxStr) != CoordBoxOpen)
  155.       CoordinateBox(hWnd);
  156.    NoSave = FALSE;
  157. }
  158.  
  159. void SaveParameters(HWND hWnd) {
  160.    BOOL Status;
  161.  
  162.    Status = (ZoomMode == IDM_ZOOMOUT);
  163.    SaveParamSwitch(ZoomOutStr, Status);
  164. }
  165.